package com.ruoyi.web.controller.gcgl;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gcgl.domain.GcProjectGroup;
import com.ruoyi.gcgl.service.IGcProjectGroupService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目框架协议Controller
 * 
 * @author ruoyi
 * @date 2024-05-19
 */
@Controller
@RequestMapping("/gcgl/group")
public class GcProjectGroupController extends BaseController
{
    private String prefix = "gcgl/group";

    @Autowired
    private IGcProjectGroupService gcProjectGroupService;

    @RequiresPermissions("gcgl:group:view")
    @GetMapping()
    public String group()
    {
        return prefix + "/group";
    }

    /**
     * 查询项目框架协议列表
     */
    @RequiresPermissions("gcgl:group:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcProjectGroup gcProjectGroup)
    {
        startPage();
        List<GcProjectGroup> list = gcProjectGroupService.selectGcProjectGroupList(gcProjectGroup);
        return getDataTable(list);
    }

    /**
     * 导出项目框架协议列表
     */
    @RequiresPermissions("gcgl:group:export")
    @Log(title = "项目框架协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcProjectGroup gcProjectGroup)
    {
        List<GcProjectGroup> list = gcProjectGroupService.selectGcProjectGroupList(gcProjectGroup);
        ExcelUtil<GcProjectGroup> util = new ExcelUtil<GcProjectGroup>(GcProjectGroup.class);
        return util.exportExcel(list, "项目框架协议数据");
    }

    /**
     * 新增项目框架协议
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目框架协议
     */
    @RequiresPermissions("gcgl:group:add")
    @Log(title = "项目框架协议", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public synchronized AjaxResult addSave(GcProjectGroup gcProjectGroup)
    {
    	gcProjectGroup.setDeleteFlag(1);
    	gcProjectGroup.setCreateUser(getLoginName());
    	gcProjectGroup.setCreateAt(new Date());
    	gcProjectGroup.setUpdateAt(new Date());
    	gcProjectGroup.setUpdateUser(getLoginName());
        return toAjax(gcProjectGroupService.insertGcProjectGroup(gcProjectGroup));
    }

    /**
     * 修改项目框架协议
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcProjectGroup gcProjectGroup = gcProjectGroupService.selectGcProjectGroupById(id);
        mmap.put("gcProjectGroup", gcProjectGroup);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目框架协议
     */
    @Log(title = "项目框架协议", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GcProjectGroup gcProjectGroup)
    {
    	gcProjectGroup.setUpdateAt(new Date());
    	gcProjectGroup.setUpdateUser(getLoginName());
        return toAjax(gcProjectGroupService.updateGcProjectGroup(gcProjectGroup));
    }

    /**
     * 删除项目框架协议
     */
    @RequiresPermissions("gcgl:group:remove")
    @Log(title = "项目框架协议", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcProjectGroupService.deleteGcProjectGroupByIds(ids));
    }
}